<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateCommissionLogTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('commission_log', ['engine' => 'InnoDB', 'comment' => '佣金变动日志表']);
        $table->addColumn('user_id', 'integer', ['null' => false, 'comment' => '用户ID'])
            ->addColumn('amount', 'decimal', ['precision' => 10, 'scale' => 2, 'null' => false, 'comment' => '变动金额'])
            ->addColumn('before', 'decimal', ['precision' => 10, 'scale' => 2, 'null' => false, 'comment' => '变动前金额'])
            ->addColumn('after', 'decimal', ['precision' => 10, 'scale' => 2, 'null' => false, 'comment' => '变动后金额'])
            ->addColumn('type', 'integer', ['null' => false, 'comment' => '类型：1-收入，2-退还，3-提现'])
            ->addColumn('remark', 'string', ['limit' => 255, 'null' => true, 'comment' => '备注'])
            ->addColumn('create_time', 'datetime', ['null' => false, 'comment' => '创建时间'])
            ->addIndex(['user_id'], ['name' => 'idx_user_id'])
            ->addIndex(['type'], ['name' => 'idx_type'])
            ->create();
    }
} 